package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.Travelcontent;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import com.sun.tracing.dtrace.Attributes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 游记资源管理控制器
 */
@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    ITravelService travelService;

    /**
     * 待审核游记资源管理
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/auditList")
    public String auditquery(@ModelAttribute("qo") TravelQueryObject qo, Model model){
        //如果是第一次查询,默认查询审核状态
        if (qo.getState() == null) {
            qo.setState(1);
        }
        qo.setOrderBy("lastUpdateTime desc");//按照最后更新事件倒叙排列
        model.addAttribute("pageInfo",travelService.query(qo));
        return "travel/auditList";
    }

    /**
     * 已发布游记资源管理
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/releaseList")
    public String releasequery(TravelQueryObject qo, Model model){
        //默认查询发布状态
        qo.setState(2);
        qo.setOrderBy("releaseTime desc");//按照最后更新事件倒叙排列
        model.addAttribute("pageInfo",travelService.query(qo));
        return "travel/releaseList";
    }

    /**
     * 获取文章内容
     * @param id
     * @return
     */
    @RequestMapping("/concent")
    @ResponseBody
    public Travelcontent getContent(Long id){
        Travelcontent travelcontent = travelService.getContentById(id);
        return travelcontent;
    }

    /**
     * 修改游记状态
     * @param travel
     * @return
     */
    @RequestMapping("/changeState")
    @ResponseBody
    public JSONResult changeState(Travel travel){
        travelService.changeState(travel);
        return new JSONResult();
    }
}
